import { useReducer } from 'react';

const initialState = <%- JSON.stringify(state) %>;

const reducer = (state, action) => {
  const {type, ...resetState} = action;
  switch (type) {
    case 'update':
      return {...state, ...resetState};
    default:
      throw('未定义此类型的操作')
  }
}
export const useInternalReducer = () => {
  const [state, dispatch] = useReducer(reducer, initialState);
  return [state, (newState) => dispatch({ type: 'update', ...newState })]
}